package com.ymatou.iapi.productmanager.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.BrandDto;
import com.ymatou.iapi.productmanager.parameter.CategoryDto;
import com.ymatou.iapi.productmanager.parameter.CategorysDto;
import com.ymatou.iapi.productmanager.parameter.GetUserBrandAndCategorysBean;
import com.ymatou.iapi.productmanager.service.GetUserBrandAndCategorysCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取买手所有的品牌和类目
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserBrandAndCategorys{
	private static GetUserBrandAndCategorysBean getuserbrandandcategorysBean;
	private static GetUserBrandAndCategorysCall getuserbrandandcategorysCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手所有的品牌和类目");
	}

	@Before
	public void caseUp() {
		getuserbrandandcategorysBean=new GetUserBrandAndCategorysBean();
		getuserbrandandcategorysCall=new GetUserBrandAndCategorysCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserbrandandcategorysCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Ts_GetUserBrandAndCategorys_001() {
		Logger.start(true,"获取买手所有的品牌和类目");
		try {
			getuserbrandandcategorysBean.setUserId(20323792);
			getuserbrandandcategorysCall.setData(getuserbrandandcategorysBean);
			checkUserBrandAndCategorys(sellerId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Ts_GetUserBrandAndCategorys_002() {
		Logger.start(true,"获取买手所有的品牌和类目,不传买手编号列表");
		try {
			getuserbrandandcategorysCall.setData(getuserbrandandcategorysBean);
			getuserbrandandcategorysCall.callService();
			Logger.verifyEquals("400", getuserbrandandcategorysCall.getString("Code"), "验证Code");
			//checkUserBrandAndCategorys(sellerId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	public void checkUserBrandAndCategorys(Integer userId) throws InterruptedException, ClientProtocolException, IOException{
		getuserbrandandcategorysCall.callService();
		List<BrandDto> sbrands = getuserbrandandcategorysCall.getBrands();
		List<Map> brands = new YmtProductsIWapper().getBrands(userId);
		for(int i = 0;i<sbrands.size();i++){
			for(int j = 0;j<brands.size();j++){
				if(sbrands.get(i).getBrandId() == (Integer)brands.get(j).get("BrandId")){
					Logger.verifyEquals(sbrands.get(i).getBrandName(), brands.get(j).get("BrandName").toString(), "验证BrandName");
					Logger.verifyEquals(sbrands.get(i).getBrandEName(), brands.get(j).get("BrandEName").toString(), "验证过BrandEName");
				}
			}
		}
	}
}